#include <stdio.h>

/**
 * 从键盘和文件读入字符串
 */
int main() {

	char a[40], b[3][60], c[4][100], d[50], e[30];
	FILE *input_stream = fopen("C7_4.IN", "r");
	FILE *output_stream = fopen("C7_4.OUT", "w");

	printf("******* Section 1 for Array a[] ********\n");
	printf("Enter a line of text for a[]\n");
	// gets 函数从键盘读取字符直到遇到回车符
	gets(a);
	puts(a);
	putchar('\n');

	printf("******* Section 2 for Array b[][] *********\n");
	printf("Type 3 lines for b[] and press return at the and of each one\n");
	for (int i = 0; i < 3; i++) {
		// 利用循环填充二维数组
		gets(b[i]);
		puts(b[i]);
	}
	putchar('\n');


	printf("****** Section 3 for Array c[][] ********\n");
	printf("We will read c[] form a file\n");
	for (int i = 0; i < 4; i++) {
		// MaxCount 为最大字符数
		fgets(c[i], 100, input_stream);
		puts(c[i]);
		// 写入到文件中
		fputs(c[i], output_stream);
	}
	putchar('\n');

	printf("******** Section 4 for Arrays d[] and e[] ********\n");
	printf("Enter a line of text for d[] and press return\n");
	scanf("%s", d);
	puts(d);
	gets(e);
	printf("This is the rest of the text entered\n");
	puts(e);

	fclose(input_stream);
	fclose(output_stream);
}